local socket = require "skynet.socket"
local proto_manager = require "common.proto_manager"
local message_packet = require "common.message_packet"

local Client = {}

-- 客户端状态
Client.State = {
    None = 0,     -- 未登录
    Logined = 1,  -- 已登录
}

function Client:new(fd)
    local o = {
        fd = fd or nil,
        state = Client.State.None,
        alivetime = 0,
    }
    setmetatable(o,self)
    self.__index = self
    return o
end

function Client:setAlivetime(t)
    self.alivetime = t
end

function Client:getAlivetime()
    return self.alivetime
end

function Client:getFd()
    return self.fd
end

function Client:isLogined()
    return Client.State.Logined == self.state
end

function Client:setLogined()
    self.state = Client.State.Logined
end

function Client:sendRawMessage(buf)
    return socket.write(self.fd,buf)
end

function Client:sendMessage(id,t,message)
    local pack = message_packet.packSendBuffer(id,t,message)
    socket.write(self.fd, pack)
end

return Client